package com.kunbo.cn.controller.core.sale;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.kunbo.cn.entity.core.sale.SaleOrderQuantityAdjust;
import com.kunbo.cn.entity.core.sale.SaleWaybillQuantityAdjust;
import com.kunbo.cn.service.core.sale.SaleOrderQuantityAdjustService;
import com.kunbo.cn.service.core.sale.SaleWaybillQuantityAdjustService;
import com.kunbo.cn.util.retu.BuildBean;
import com.kunbo.cn.util.retu.BuildBean1;
import com.kunbo.cn.util.retu.CommonResult;
import com.kunbo.cn.util.retu.Pages;
import com.kunbo.cn.util.retu.ResultBean;
import com.kunbo.cn.util.retu.ResultBean1;

/**
 *
 * @author bjl  
 * @date 2019年4月21日 
 */
@RestController  
@RequestMapping("/SaleWaybillQuantityAdjust") 
public class SaleWaybillQuantityAdjustController {
	@Autowired
    private JdbcTemplate jdbcTemplate;
	@Autowired
	private SaleWaybillQuantityAdjustService service;
	/**
	 * 新增销售调量记录
	 * 
	 */
	@PostMapping("/save")
	public CommonResult add(SaleWaybillQuantityAdjust swqa) {
		service.save(swqa);
		return new CommonResult(true,"操作成功",null);
	}
	/**
	 * 获取销售运单调量历史list
	 * @param code
	 * @param materialType
	 * @param page
	 * @param pageSize
	 * @return
	 */
	@PostMapping("/list")
	public ResultBean<List<Map<String,Object>>> list(
			@RequestParam("sale_waybill_code")String sale_waybill_code 
			){
		ResultBean<List<Map<String,Object>>> result = new ResultBean<List<Map<String,Object>>>();
		return BuildBean.buildResult(result, "success", "error", service.list(sale_waybill_code));//id
	
}
	/**
	 * 获取销售运单
	 * @param page
	 * @param pageSize
	 * @return
	 *//*
	@PostMapping("/WaybillList")
	public ResultBean1<List<Map<String,Object>>> OrderList(
			@RequestParam("page")Integer page,
			@RequestParam("pageSize")Integer pageSize
			){
		ResultBean<List<Map<String,Object>>> result = new ResultBean<List<Map<String,Object>>>();
		ResultBean1<List<Map<String,Object>>> result1 = new ResultBean1<List<Map<String,Object>>>();
		ResultBean<List<Map<String,Object>>>njks=BuildBean.buildResult(result, "success", "error", service.WaybillList());//id
		int total=njks.getData().size();
		return BuildBean1.buildResult(result1, "success", "error",total,service.WaybillList());//id
}*/
	/**
	 * 获取销售运单
	 * @param page
	 * @param pageSize
	 * @return
	 */
	@PostMapping("/WaybillList")
	public ResultBean1<Pages> OrderList(
			@RequestParam("page")Integer page,
			@RequestParam("pageSize")Integer pageSize
			){
		ResultBean1<Pages> result = new ResultBean1<Pages>();
		return BuildBean1.buildResulttoPages(result, "success", "error",service.WaybillList1(page,pageSize));//id
}
	/**
	 *订单量调整
	 * 
	 */
  @PostMapping("/AdjustWaybillNum")//Adjust
   public int AdjustOrderNum(HttpServletRequest request,HttpServletResponse response) throws SQLException{
	   String waybill_code  = request.getParameter("waybill_code"); //订单编号
	   String trans_total = request.getParameter("trans_total");//合同总量
	   String capacity_to_be_transported=request.getParameter("capacity_to_be_transported");//待运量
	   String adjust_amount=request.getParameter("adjust_amount");//调整量
	   return service.AdjustWaybillNum(waybill_code,trans_total,capacity_to_be_transported,adjust_amount);
  }
  /**
	*执行量调整
	* 
	*/
@PostMapping("/AdjustExecutedNum")//Adjust
 public int AdjustExecutedNum(HttpServletRequest request,HttpServletResponse response) throws SQLException{
	   String waybill_code  = request.getParameter("waybill_code"); //运单编号
	   String executed_amount = request.getParameter("executed_amount");//待执行量
	   String capacity_to_be_transported=request.getParameter("capacity_to_be_transported");//待运量
	   String adjust_amount=request.getParameter("adjust_amount");//调整量
	   return service.AdjustExecutedNum(waybill_code,executed_amount,capacity_to_be_transported,adjust_amount);
}
}
